package com.pharmacy.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pharmacy.dto.AddOrdersDto;
import com.pharmacy.dto.OrdersPageSelectDto;
import com.pharmacy.dto.UpdateOrdersDto;
import com.pharmacy.entity.Orders;
import com.pharmacy.entity.WeeklyData;
import com.pharmacy.mapper.OrdersMapper;
import com.pharmacy.result.PageResult;
import com.pharmacy.service.OrdersService;
import com.pharmacy.vo.TodayDate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersMapper ordersMapper;


    /**
     * 添加订单
     * @param addOrdersDto
     */
    @Override
    public void addOrders(AddOrdersDto addOrdersDto) {


        Orders orders = new Orders();
        BeanUtils.copyProperties(addOrdersDto,orders);
        orders.setBuyDate(LocalDateTime.now());
        ordersMapper.addOrders(orders);
    }

    /**
     * 订单分页查询
     * @param ordersPageSelectDto
     */
    @Override
    public PageResult pageSelect(OrdersPageSelectDto ordersPageSelectDto) {
        PageHelper.startPage(ordersPageSelectDto.getPage(),ordersPageSelectDto.getPageSize());
        Page<Orders> page = ordersMapper.pageSelect(ordersPageSelectDto);
        long total = page.getTotal();
        List<Orders> records = page.getResult();
        return new PageResult(total,records);
    }

    /**
     * 删除订单
     * @param orderId
     */
    @Override
    public void deleteOrders(Integer orderId) {
        ordersMapper.deleteOrders(orderId);
    }

    /**
     * 修改订单
     * @param updateOrdersDto
     */
    @Override
    public void updateOrders(UpdateOrdersDto updateOrdersDto) {
        ordersMapper.updateOrders(updateOrdersDto);

    }

    /**
     * 查询今日订单
     * @param parsedDate
     * @return
     */
    @Override
    public TodayDate selectTodayDate(LocalDate parsedDate) {
        TodayDate todayDate = ordersMapper.todayDate(parsedDate);
        return todayDate;
    }

    @Override
    public WeeklyData weeklyData() {
        WeeklyData weeklyData = ordersMapper.weeklyData();
        return weeklyData;
    }

    @Override
    public void updateWeeklyData(String date) {
        WeeklyData weeklyData = new WeeklyData();

    }
}
